package com.paradogs.generator;

import com.paradogs.common.utils.SpringUtils;
import com.paradogs.generator.protobuf.ProtoFileSelector;
import com.paradogs.generator.protobuf.ProtobufConfig;
import org.apache.commons.io.FileUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.util.ResourceUtils;

import java.io.File;

/**
 * @author: yumi
 * @date: 2024/10/14  14:07
 * @Description: TODO
 */
@SpringBootApplication
public class GenProtoFile {
    public static void main(String[] args) throws Exception {
        SpringApplication.run(GenProtoFile.class, args);
        // 读取配置
        ProtobufConfig config = SpringUtils.getBean(ProtobufConfig.class);

        // 重置文件夹
        File file = ResourceUtils.getFile(config.getOutdir());
        if (file.exists()) { FileUtils.deleteDirectory(file); }

        // 生成文件
        ProtoFileSelector selector = SpringUtils.getBean(ProtoFileSelector.class);
        selector.setGeneratorDir(config.getOutdir());
        selector.setScanPackages(config.getScanPackages());
        selector.scanAndHandle();

    }
}
